package blazingbubble.network.game.strategy;

import java.util.HashMap;

public class PlayerTeamJoinBuffer {
	public HashMap<Long, BufferedJoin> bufferedJoins = new HashMap<Long, BufferedJoin>();

	public void buffer(long clientId, int teamIndex, int slotIndex, long timeStamp) {
		BufferedJoin bufferedJoin = bufferedJoins.get(clientId);
		//buffer the join data if we don't have an entry for this client yet or it is more recent (later time stamp)
		if(bufferedJoin == null || timeStamp > bufferedJoin.getTimeStamp()) {
			bufferedJoins.put(clientId, new BufferedJoin(teamIndex, slotIndex, timeStamp));
		}
	}

	public BufferedJoin remove(long clientId) {
		return bufferedJoins.remove(clientId);
	}

	public static class BufferedJoin {
		int teamIndex;
		int slotIndex;
		long timeStamp;

		public BufferedJoin(int teamIndex, int slotIndex, long timeStamp) {
			this.teamIndex = teamIndex;
			this.slotIndex = slotIndex;
			this.timeStamp = timeStamp;
		}

		public int getTeamIndex() {
			return teamIndex;
		}

		public int getSlotIndex() {
			return slotIndex;
		}

		long getTimeStamp() {
			return timeStamp;
		}
	}
}
